package com.ComputerSales.controller;


import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.ComputerSales.entity.Cart;
import com.ComputerSales.service.ICartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.Shutdown;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者
 * @since 2024-06-26
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private ICartService cartService;

    @PostMapping
    public SaResult addCart(Cart cart) {
        cart.setQuantity(1);
        cart.setUserId(StpUtil.getLoginIdAsInt());
        cartService.save(cart);
        return SaResult.ok();
    }

    @GetMapping("/remove/{id}")
    public SaResult removeCart(@PathVariable Integer id) {
        cartService.removeById(id);
        return SaResult.ok();
    }

}
